package com.atguigu.tingshu.album.mapper;

import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.query.album.TrackInfoQuery;
import com.atguigu.tingshu.vo.album.AlbumTrackListVo;
import com.atguigu.tingshu.vo.album.TrackListVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface TrackInfoMapper extends BaseMapper<TrackInfo> {

    /**
     * @author gengjian
     * @date 2025/02/22 15:57:52
     * 分页查询声音列表
     */
    IPage<TrackListVo> selectUserTrackPage(Page<TrackListVo> page, @Param("trackInfoQuery") TrackInfoQuery trackInfoQuery);

    /**
     * @author gengjian
     * @date 2025/02/23 14:49:02
     * 有个业务就是说我删除了专辑中一条声音，对应的其他声音比被删除声音排序靠后的（大的）在专辑中排序会往前移动一位
     * 修改其他声音的排序
     */
    @Update("update from track_info set order_num = order_num - 1 where album_id = #{albumId} and order_num > #{orderNum} and is_deleted=0")
    void updateOrderNum(@Param("albumId") Long albumId, @Param("orderNum") Integer orderNum);

    /**
     * @author gengjian
     * @date 2025/03/03 19:09:10
     * 根据专辑id分页查询声音列表
     */
    IPage<AlbumTrackListVo> selectAlbumTrackPage(Page<AlbumTrackListVo> page, Long albumId);
}
